package com.zkingsoft.services.impl;

import com.zkingsoft.services.MeetingService;
import com.zkingsoft.plugin.pojo.PaginationVO;
import com.zkingsoft.model.Meeting;
import com.zkingsoft.model.MeetingContent;
import com.zkingsoft.dao.MeetingContentDao;
import com.zkingsoft.dao.MeetingDao;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2016-11-24 14:24
 */
@Service("meetingService")
public class  MeetingServiceImpl implements    MeetingService  {

	
	@Autowired
	private MeetingDao meetingDao;
	@Autowired
	private MeetingContentDao meetingContentDao;
	
	@Transactional
	@Override
	public int add(Meeting meeting){
		int i = meetingDao.insert(meeting);
		List<String> list = meeting.getContent();
		if(list.size()>0){
			 int indexFlag=0;
			for(int j=0;j<list.size();j++){
				if(list.get(j) != null && list.get(j) !=""){
					indexFlag++;
					MeetingContent meetingContent=new MeetingContent();
					meetingContent.setMeetingId(meeting.getId());
					meetingContent.setOrderby(indexFlag);
					meetingContent.setContent(list.get(j));
					meetingContentDao.insert(meetingContent);
				}
			}
		}
		return i;
	}
	@Transactional
    @Override
	public int modify(Meeting meeting){
		MeetingContent meetingContent=new MeetingContent();
		meetingContent.setMeetingId(meeting.getId());
		meetingContentDao.deleteByModel(meetingContent);
		List<String> list = meeting.getContent();
		if(list.size()>0){
			 int indexFlag=0;
				for(int j=0;j<list.size();j++){
					if(list.get(j) != null && list.get(j) !=""){
						indexFlag++;
						MeetingContent meetingContent1=new MeetingContent();
						meetingContent1.setMeetingId(meeting.getId());
						meetingContent1.setOrderby(indexFlag);
						meetingContent1.setContent(list.get(j));
						meetingContentDao.insert(meetingContent1);
					}
				}
		}
		return meetingDao.update(meeting);
	}
	
    @Transactional
	@Override
	public int remove(List<Long> list){
    	for(Long meetingId:list){
    		MeetingContent meetingContent=new MeetingContent();
    		meetingContent.setMeetingId(meetingId);
    		meetingContentDao.deleteByModel(meetingContent);
    	}

		return meetingDao.deleteByIds(list);
	
	}
    
    @Transactional
	@Override
	public int removeById(Long id){
		MeetingContent meetingContent=new MeetingContent();
		meetingContent.setMeetingId(id);
		meetingContentDao.deleteByModel(meetingContent);
		return meetingDao.deleteById(id);
	
	}
	
	@Override
	public int removeByModel(Meeting meeting){
	
		return meetingDao.deleteByModel(meeting);
	
	}
	
	
	@Override
	public List<Meeting> findInPage(Meeting meeting,  PaginationVO pageVo){
	
		return meetingDao.selectInPage(meeting , pageVo);
	
	}
	
	@Override
	public List<Meeting> findByModel(Meeting meeting){
	
		return meetingDao.selectByModel(meeting);
	
	}
	
	@Override
	public int  findTotal(Meeting meeting){
	
		return meetingDao.selectTotalRecord(meeting);
	
	}
	@Transactional
	@Override
	public Meeting  findById(Long id){
		Meeting meeting = meetingDao.selectById(id);
		MeetingContent meetingContent=new MeetingContent();
		meetingContent.setMeetingId(id);
		meeting.setMeetingContent1(meetingContentDao.selectByModel(meetingContent));
		return meeting;
	
	}

   	
	
	
}